import { Body, Controller, Inject, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { MailService } from '../service/MailService';

/*
 * @Author: jingfuu@163.com
 * @Date: 2024-11-14 15:58:03
 * @LastEditTime: 2024-11-20 14:17:10
 * @Description: file content
 */
@ApiTags('邮件发送')
@Controller('mail')
class MailSendController {
  @Inject()
  private mailService: MailService;

  @ApiOperation({ summary: '测试发送邮件' })
  @Post('send-test')
  async sendWelcomeEmail(@Body() body: { email: string; name: string }) {
    const to = body.email;
    const subject = 'Welcome to Our Platform';
    const templatePath = '../../../views/test.ejs'; // 注意路径
    const context = { message: body.name };

    await this.mailService.sendMail(to, subject, templatePath, context);
    return { message: 'Email sent successfully' };
  }
}
export default MailSendController;
